 <link rel="stylesheet" type="text/css" href="css/validationEngine.jquery.css">
<link rel="stylesheet" type="text/css" href="css/template.css">

<script type="text/javascript" src="js/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="js/jquery.validationEngine-vi.js"></script>
<script type="text/javascript" src="js/jquery.validationEngine.js"></script>
<script>
        jQuery(document).ready(function(){
            // binds form submission and fields to the validation engine
            jQuery("#formID").validationEngine();
        });
</script>
<script>
function Del_Info(str){
	var q=confirm('Bạn có chắc chắn muốn xóa hay không?');	
	if(q==true) 
		window.location=str;
	
}
</script>
<?php
$sql="SELECT substr( QUYEN,3,1 ) as mq
FROM qldl_tai_khoan
WHERE ten_dang_nhap = '".$_SESSION['username']."'";
	$query = @mysql_query($sql,$conn);
	$row = @mysql_fetch_array($query);
	if($row['mq']==1){
	 @header('Location: index.php?page=dia_diem'); 
	}
	else {
	echo  "<script>alert ('Bạn không có quyền truy cập trang này!')</script>"; 
	echo "<meta http-equiv='refresh' content='0;url= index.php'>";
	}
?>
<?php
			

			$sql1="select max(MA_DIA_DIEM) from qldl_dia_diem_du_lich "; 
			$result=mysql_query($sql1); 
			$kq=mysql_fetch_array($result); 
			$ma=$kq[0]+1; 
				?>
<div class="cpanel-right-tttk">
  <div id="panel-sliders" class="pane-sliders">
    <div class="panel">
      <table width="100%" border="0" cellspacing="0" cellpadding="0" style=" padding:10px;">
        <thead>
        <tr style=" padding-bottom:10px;">
        <th colspan="3" align="left" style="padding-bottom:10px;">QUẢN LÍ DANH MỤC ĐỊA ĐIỂM DU LỊCH</th>
        </tr> 
        </thead> 
        <tr valign="top" style="padding:5px;">
          <td width="46%" rowspan="2"><div style=" padding:0px; border-top: medium none; border-bottom: medium none; overflow: hidden; height: auto; width:100%" align="left">
            <form name="formID" id="formID" action="" method="post" enctype="multipart/form-data">
            <table width="96%" border="1" bordercolor="#666666" class="adminlist_tt">
              <thead>
                <tr>
                  <th colspan="3" align="center"> Thông tin thêm điểm du lịch</th>
                </tr>
              </thead>
              <tbody>
                
             
                <tr>
                  <td>Mã tỉnh/thành phố</td>
                  <td colspan="2">
                    <label for="list_ma_thanh_pho"></label>
                    <select id="chon_ttp" name="chon_ttp">
						<?php 
							$sql_ttp="select * from qldl_tinh_thanh_pho order by MA_TP asc";
							$query_ttp = @mysql_query($sql_ttp,$conn);	
							if($query_ttp)while($row_ttp = @mysql_fetch_array($query_ttp)){
						?>  
						<option value="<?php echo $row_ttp['MA_TP'];?>"><?php echo $row_ttp['THANH_PHO'];?></option>
							<?php }?> 
					</select>
                  </td>
                </tr>
                <tr>
                  <td>Điểm du lịch</td>
                  <td colspan="2"><label for="checkbox">
                    <input type="text" class="validate[required] text-input" name="txt_dia_diem" id="txt_dia_diem" />
                  </label></td>
                </tr>
                <tr>
                  <td height="26">Thông tin</td>
                  <td colspan="2">
                      <textarea name="area" id="area" style="height:100px; width:100%;"></textarea>
                    </td>
                </tr>
                <tr>
                  <td>Hình ảnh</td>
                  <td colspan="2">
                      <input type="file" name="file_up" />
                   </td>
                </tr>
                <tr>
                  <td height="37" colspan="3">Hấp dẫn
                    <input type="checkbox" name="ck_hd" id="ck_hd" value="1" /></td>
                  </tr>
                <tr>
                  <td colspan="3">
                    <input type="submit" name="btn_them_diem_du_lich" id="btn_them_diem_du_lich" value="Lưu" />
                    <input type="reset" name="Reset" id="button" value="Hủy" onclick='window.location.href="index.php?page=dia_diem"' />
                  
                  <?php
				  if(isset($_POST['btn_them_diem_du_lich'])){
					$madd = $_POST['txt_ma_dia_diem'];
					$ttp = $_POST['chon_ttp'];
					$dddl = $_POST['txt_dia_diem'];
					$tt = $_POST['area'];
					if(isset($_POST['ck_hd']))
					$hd = $_POST['ck_hd'];
					else $hd=0;
					  if ($_FILES["file_up"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file_up"]["error"] . "<br />";
    }
  else
    { $link =$_FILES["file_up"]["name"];
    if (file_exists("dia_diem/upload/news/" . $_FILES["file_up"]["name"]))
      {
      echo $_FILES["file_up"]["name"] . " da ton tai file tren server. ";
      }
    else
      {  
      move_uploaded_file($_FILES["file_up"]["tmp_name"],
      "dia_diem/upload/news/" . $_FILES["file_up"]["name"]);	
	  

      }
	}

					$sql = "INSERT INTO qldl_dia_diem_du_lich VALUES('$ma','$ttp','$dddl','$hd','$tt','$link')";
	  				$query = @mysql_query($sql,$conn);
						if($query)echo "<script>alert ('Thêm thông tin thành công.')</script>";	
						else echo "<script> alert ('Thêm không thành công!')</script>";

					}

	  		?>
                  </td>
                  </tr>
                  
              </tbody>
            </table>
            </form>
          </div></td>
          <td width="54%"><div style=" padding:0px; border-top: medium none; border-bottom: medium none; overflow: hidden; height: auto; width:100%" align="left">
            <table width="100%" border="1" bordercolor="#666666" class="adminlist_tt">
              <thead>
                <tr>
                  <th colspan="5" align="center"> Danh sách điểm du lịch</th>
                <?php include('dia_diem/del.php'); ?>
                </tr>
              </thead>
              <tbody>
               <form action="" method="post" name="form_view" id="form_view">
                <tr>
                
                  <td width="70" align="center">Mã điểm du lịch</td>
                  <td width="86" align="center">Mã thành phố</td>
                  <td width="138" align="center">Điểm du lịch</td>
                  <td width="131" align="center">Link ảnh</td>
                  <td width="88">Cập nhật</td>
                </tr>
                <?php
				$stt=0;
	$sql="select * from qldl_dia_diem_du_lich a,qldl_tinh_thanh_pho b where a.MA_TP = b.MA_TP ";
	$query = @mysql_query($sql,$conn);	
	if(!$query) echo "Query error to display.";
	else while($row = @mysql_fetch_array($query)){
		$stt++;
			?>	 
                <tr>
                
                  <td><?php echo $row['MA_DIA_DIEM'];?></td>
                  <td><?php echo $row['MA_TP'];?></td>
                  <td><?php echo $row['DIA_DIEM'];?></td>
                  <td><?php echo $row['HINH_ANH'];?></td>
                  <td><a href="index.php?page=id_edit_dd&amp;id_edit_dd=<?php echo $row['MA_DIA_DIEM'];?>&amp;&id_ttp=<?php echo $row['MA_TP'];?>">Sửa</a> || 
                  <a onclick="Del_Info('index.php?page=dia_diem&amp;id_del_dd=<?php echo $row['MA_DIA_DIEM']; ?>&amp;id_photo_dd=<?php echo $row['HINH_ANH']; ?>');" href="#">Xóa</a></td>
                </tr>
				<?php	}
                ?>
                </form>
              </tbody>
            </table>
          </div></td>
        </tr>
      </table>
    </div>
  </div>
</div>